package com.example.park2212

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.JavascriptInterface
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.lib_base.mvvm.BaseViewActivity
import com.example.park2212.databinding.ActivityWebViewBinding
import com.tencent.smtt.sdk.WebView
import dagger.hilt.android.AndroidEntryPoint
import kotlin.io.path.Path

@AndroidEntryPoint
@Route(path = "/app/WebViewActivity")
class WebViewActivity : BaseViewActivity<ActivityWebViewBinding>() {
    var web: WebView?=null
    override fun initView() {
        web = binding.web
        binding.web.apply {
            loadUrl("file:///android_asset/index.html")
            settings.javaScriptEnabled = true //允许和js交互

            //js调安卓步骤1
            addJavascriptInterface(this@WebViewActivity,"android")
        }

        binding.btnJs.setOnClickListener {
            //安卓调用js --第1步
            web?.loadUrl("javascript:harmonyCallJS()")
        }
    }

    override fun initData() {

    }

    //js调安卓步骤2
    @JavascriptInterface
    fun harmonyosAgree():String{
        return "hello"
    }

}